<template>
    <li @mouseenter="isShow = true" @mouseleave="isShow = false" :class="isShow && 'active'">
        <label>
            <input type="checkbox" :checked="todo.isDone" @click="updataOneChecked" />
            <span>{{ todo.content }}</span>
        </label>
        <button @click="deleteOneTodo" v-show="isShow" class="btn btn-danger">删除</button>
    </li>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
    name: 'Item'
})
</script>
<script lang="ts" setup>
import type { TodoData } from '@/App.vue';
import { ref } from 'vue';
const isShow = ref(false)
const props = defineProps<{
    todo: TodoData,
    updataOneChecked: (index: number) => void,
    index: number,
    deleteOneTodo(index: number): void
}>()

const updataOneChecked = () => {
    props.updataOneChecked(props.index)
}

const deleteOneTodo = () => {
    props.deleteOneTodo(props.index)
}
</script>

<style lang="less" scoped>
/*item*/
li {
    list-style: none;
    height: 36px;
    line-height: 36px;
    padding: 0 5px;
    border-bottom: 1px solid #ddd;
}

li.active {
    background-color: skyblue;
}

li label {
    float: left;
    cursor: pointer;
}

li label li input {
    vertical-align: middle;
    margin-right: 6px;
    position: relative;
    top: -1px;
}

li button {
    float: right;
    margin-top: 3px;
}

li:before {
    content: initial;
}

li:last-child {
    border-bottom: none;
}
</style>